package com.example.light;

import com.github.pagehelper.PageHelper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;

import javax.servlet.MultipartConfigElement;
import org.springframework.context.annotation.Bean;

import java.util.Properties;


@SpringBootApplication
@MapperScan(basePackages = {"com.example.light.web.*.dao"})
public class LightApplication extends SpringBootServletInitializer {

    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(LightApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(LightApplication.class, args);
    }


    /**
     * @author lizhilong
     * @date 2018/8/2 14:41
     * @param
     * @return javax.servlet.MultipartConfigElement
     * @description:上传文件配置，支持最大文件5000M
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory config = new MultipartConfigFactory();
        config.setMaxFileSize("5000MB");
        config.setMaxRequestSize("9000MB");
        return config.createMultipartConfig();
    }

    @Bean
    public PageHelper pageHelper() {
        PageHelper pageHelper = new PageHelper();
        Properties properties = new Properties();
        properties.setProperty("offsetAsPageNum", "true");
        properties.setProperty("rowBoundsWithCount", "true");
        properties.setProperty("reasonable", "true");
        properties.setProperty("dialect", "mysql");    //配置mysql数据库的方言
        pageHelper.setProperties(properties);
        return pageHelper;
    }
}
